

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>bimpy - bundled imgui for python &mdash; bimpy  documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script src="_static/jquery.js"></script>
        <script src="_static/underscore.js"></script>
        <script src="_static/doctools.js"></script>
        <script src="_static/language_data.js"></script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="bimpy - References" href="bimpy.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="#" class="icon icon-home"> bimpy
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">First steps</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="bimpy.html">bimpy - References</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="#">bimpy</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="#">Docs</a> &raquo;</li>
        
      <li>bimpy - bundled imgui for python</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="bimpy-bundled-imgui-for-python">
<span id="topics-index"></span><h1>bimpy - bundled imgui for python<a class="headerlink" href="#bimpy-bundled-imgui-for-python" title="Permalink to this headline">¶</a></h1>
<div class="toctree-wrapper compound">
</div>
<p>Welcome to bimpy   documentation!</p>
<div class="section" id="api-bimpy">
<h2>API: <a class="reference internal" href="bimpy.html"><span class="doc">bimpy - References</span></a><a class="headerlink" href="#api-bimpy" title="Permalink to this headline">¶</a></h2>
<p><a class="reference external" href="https://pepy.tech/project/bimpy"><img alt="Downloads" src="https://pepy.tech/badge/bimpy" /></a>
<a class="reference external" href="https://api.travis-ci.com/podgorskiy/bimpy.svg?branch=master"><img alt="Build" src="https://travis-ci.org/podgorskiy/bimpy.svg?branch=master" /></a>
<img alt="License" src="https://img.shields.io/badge/License-MIT-yellow.svg" /></p>
<p><strong>bimpy</strong> is a python module that provides bindings to <a class="reference external" href="https://github.com/ocornut/imgui">dear imgui</a> and distributed as a self-contained package bundled with <a class="reference external" href="https://github.com/glfw/glfw">glfw</a> and <a class="reference external" href="https://github.com/skaslev/gl3w">gl3w</a>.</p>
<p>Features:</p>
<ul class="simple">
<li><p>Allows to create immediate mode UI with python easily. The API is kept as close to the original dear imgui as possible.</p></li>
<li><p><strong>bimpy</strong> already has all necessary functionality for window/OpenGL context creation and hides those details from the user.</p></li>
<li><p><strong>bimpy</strong> supports multiple contexts and allows creating multiple windows.</p></li>
<li><p><strong>bimpy</strong> works on Windows, GNU Linux, and macOS.</p></li>
<li><p><strong>bimpy</strong> does not have dependencies and can be easely built from sources. Building relies only on distutils.</p></li>
<li><p><strong>bimpy</strong> can display images from ndarrays, PIL Images, numpy arrays, etc.,</p></li>
</ul>
<p>Hello-world with bimpy:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">bimpy</span>

<span class="n">ctx</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Context</span><span class="p">()</span>

<span class="n">ctx</span><span class="o">.</span><span class="n">init</span><span class="p">(</span><span class="mi">600</span><span class="p">,</span> <span class="mi">600</span><span class="p">,</span> <span class="s2">&quot;Hello&quot;</span><span class="p">)</span>

<span class="nb">str</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">String</span><span class="p">()</span>
<span class="n">f</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Float</span><span class="p">();</span>

<span class="k">while</span><span class="p">(</span><span class="ow">not</span> <span class="n">ctx</span><span class="o">.</span><span class="n">should_close</span><span class="p">()):</span>
        <span class="k">with</span> <span class="n">ctx</span><span class="p">:</span>
                <span class="n">bimpy</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">&quot;Hello, world!&quot;</span><span class="p">)</span>

                <span class="k">if</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">button</span><span class="p">(</span><span class="s2">&quot;OK&quot;</span><span class="p">):</span>
                        <span class="k">print</span><span class="p">(</span><span class="nb">str</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>

                <span class="n">bimpy</span><span class="o">.</span><span class="n">input_text</span><span class="p">(</span><span class="s1">&#39;string&#39;</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="mi">256</span><span class="p">)</span>

                <span class="n">bimpy</span><span class="o">.</span><span class="n">slider_float</span><span class="p">(</span><span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
</pre></div>
</div>
<div class="figure align-default">
<img alt="hello-world" src="https://i.imgur.com/rL7cFj7.png" />
</div>
<p>Display image:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">bimpy</span>
<span class="kn">from</span> <span class="nn">PIL</span> <span class="kn">import</span> <span class="n">Image</span>

<span class="n">ctx</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Context</span><span class="p">()</span>

<span class="n">ctx</span><span class="o">.</span><span class="n">init</span><span class="p">(</span><span class="mi">800</span><span class="p">,</span> <span class="mi">800</span><span class="p">,</span> <span class="s2">&quot;Image&quot;</span><span class="p">)</span>

<span class="n">image</span> <span class="o">=</span> <span class="n">Image</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;test.png&quot;</span><span class="p">)</span>

<span class="n">im</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Image</span><span class="p">(</span><span class="n">image</span><span class="p">)</span>

<span class="k">while</span><span class="p">(</span><span class="ow">not</span> <span class="n">ctx</span><span class="o">.</span><span class="n">should_close</span><span class="p">()):</span>
    <span class="k">with</span> <span class="n">ctx</span><span class="p">:</span>
        <span class="n">bimpy</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">&quot;Display PIL Image&quot;</span><span class="p">)</span>

        <span class="n">bimpy</span><span class="o">.</span><span class="n">image</span><span class="p">(</span><span class="n">im</span><span class="p">)</span>
</pre></div>
</div>
<div class="figure align-default">
<img alt="hello-world" src="https://i.imgur.com/wiDGRpr.png" />
</div>
<p>Similarly, numpy arrays with 2 dimensions, 3 dimensions (2, 3 or 4 channels) of type <strong>np.uint8</strong> can be displayed.
More examples here: <a class="reference external" href="https://github.com/podgorskiy/bimpy/blob/master/examples/image.py">https://github.com/podgorskiy/bimpy/blob/master/examples/image.py</a></p>
</div>
<div class="section" id="install">
<h2>Install<a class="headerlink" href="#install" title="Permalink to this headline">¶</a></h2>
<p>Installation is easy since the package does not have dependencies:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>pip install bimpy
</pre></div>
</div>
<p>Or you can build and install from sources:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>python setup.py install
</pre></div>
</div>
<p>All c/c++ sources are built with distutils. All you need is a compiler with C++11 support.</p>
<p>Windows users, who use python 2.7 may encounter problems, because on Windows, python 2.7 uses MSVC 9.0, which doesn’t have support for c++11. However, you still can build it with more recent MSVC (for example MSVC 14.0, which is Visual C++ 2015) using the commands below:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>call <span class="s2">&quot;%VS140COMNTOOLS%\VsDevCmd.bat&quot;</span>
<span class="nb">set</span> <span class="nv">VS90COMNTOOLS</span><span class="o">=</span>%VS140COMNTOOLS%
python setup.py install
</pre></div>
</div>
<p>If building on Linux, the following dependencies will be needed:</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>sudo apt-get install mesa-common-dev libxi-dev libxinerama-dev libxrandr-dev libxcursor-dev
</pre></div>
</div>
<p>To build all wheels for linux package distribution (manylinux) run <cite>build_manylinux_wheels.sh</cite>.</p>
<p>For testing/debugging there is a CMakeList.txt included. It is not used by setup.py, but can be handy in order to build/debug package from certain IDEs.</p>
</div>
<div class="section" id="how-to-use-it">
<h2>How to use it?<a class="headerlink" href="#how-to-use-it" title="Permalink to this headline">¶</a></h2>
<div class="section" id="intro">
<h3>Intro<a class="headerlink" href="#intro" title="Permalink to this headline">¶</a></h3>
<p><strong>bimpy</strong> is python binding for <a class="reference external" href="https://github.com/ocornut/imgui">dear imgui</a> and tries to match the C++ API. Also, it has some additional functions to create a window and some other differences.</p>
<p>It has binding for the most functions from <strong>dear imgui</strong>. All functions are renamed from <strong>CamelCase</strong> to <strong>snake_case</strong>, which is more common for python. For example <code class="docutils literal notranslate"><span class="pre">ImGui::InputText</span></code> is mapped to <code class="docutils literal notranslate"><span class="pre">bimpy.input_text</span></code>.</p>
</div>
<div class="section" id="context-and-window">
<h3>Context and window<a class="headerlink" href="#context-and-window" title="Permalink to this headline">¶</a></h3>
<p>First of all, you need to import <strong>bimpy</strong></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">bimpy</span>
</pre></div>
</div>
<p>Distinctively from <strong>dear imgui</strong>, bimpy does not have global state (<strong>dear imgui</strong> has it by default, but it has an option not to have one). So, you will need to create a context.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">ctx</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Context</span><span class="p">(</span><span class="n">width</span><span class="p">,</span> <span class="n">height</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
</pre></div>
</div>
<p>Where integers <em>width</em> and <em>height</em> specify the size of the window, and string <em>name</em> is a caption of the window.</p>
<p>All calls to <strong>bimpy</strong>’s API must be within <em>with</em> statement applied to the context object:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">ctx</span><span class="p">:</span>
        <span class="n">bimpy</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">&quot;Hello, world!&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>And there must be only one <em>with</em> statement applied to the context object per frame.</p>
<p>Or, a second option is to manualy call <code class="docutils literal notranslate"><span class="pre">ctx.new_frame()</span></code> before all API calls, and then <code class="docutils literal notranslate"><span class="pre">ctx.render()</span></code> after.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">ctx</span><span class="o">.</span><span class="n">new_frame</span><span class="p">()</span>
<span class="n">bimpy</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="s2">&quot;Hello, world!&quot;</span><span class="p">)</span>
<span class="n">ctx</span><span class="o">.</span><span class="n">render</span><span class="p">()</span>
</pre></div>
</div>
<p>You can have multiple <em>Context</em> objects for multiple windows, however, API is not thread-safe.</p>
</div>
<div class="section" id="variables">
<h3>Variables<a class="headerlink" href="#variables" title="Permalink to this headline">¶</a></h3>
<p>All <strong>imgui</strong> API that provides user input (such as <em>InputText</em>, <em>SliderFloat</em>, etc.) modifies the variable through the reference to it. However, in python, such objects as integers, floats and strings are passed always by value. Because of this, <strong>bimpy</strong> provides special wrappers, that allow passing those variables by reference.</p>
<p>For example, to use <em>slider_float</em>, you will need first to create a variable that will hold the state:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">f</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Float</span><span class="p">();</span>
</pre></div>
</div>
<p>You can access the value in the following way: <code class="docutils literal notranslate"><span class="pre">f.value</span></code></p>
<p>To use it with <em>slider_float</em> simply pass it to that function:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">bimpy</span><span class="o">.</span><span class="n">slider_float</span><span class="p">(</span><span class="s2">&quot;float slider&quot;</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
</pre></div>
</div>
<p>All <strong>imgui</strong> input functions that provide multiple inputs, like <em>SliderFloat2</em>, <em>SliderInt4</em>, <em>InputInt3</em>, etc. are mapped to equivalent functions, but instead of passing an array of variables, you need to list all variables in the argument list:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">f1</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Float</span><span class="p">();</span>
<span class="n">f2</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Float</span><span class="p">();</span>
<span class="n">f3</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Float</span><span class="p">();</span>

<span class="k">while</span><span class="p">(</span><span class="ow">not</span> <span class="n">ctx</span><span class="o">.</span><span class="n">should_close</span><span class="p">()):</span>
        <span class="k">with</span> <span class="n">ctx</span><span class="p">:</span>
                <span class="n">bimpy</span><span class="o">.</span><span class="n">slider_float3</span><span class="p">(</span><span class="s2">&quot;float&quot;</span><span class="p">,</span> <span class="n">f1</span><span class="p">,</span> <span class="n">f2</span><span class="p">,</span> <span class="n">f3</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="draw-commands">
<h3>Draw commands<a class="headerlink" href="#draw-commands" title="Permalink to this headline">¶</a></h3>
<p>Some draw commands are exposed. In contrast to C++ API, the exposed functions are not methods of <strong>ImDrawList</strong>, but global functions. All drawing functions should be called inside the <em>begin/end</em> calls of a window.</p>
<p>List of exposed drawing functions:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">add_circle</span><span class="p">(</span><span class="n">centre</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">radius</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">num_segments</span><span class="p">:</span> <span class="nb">int</span><span class="o">=</span><span class="mi">12</span><span class="p">,</span> <span class="n">thickness</span><span class="p">:</span> <span class="nb">float</span><span class="o">=</span><span class="mf">1.0</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span>
<span class="n">add_circle_filled</span><span class="p">(</span><span class="n">centre</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">radius</span><span class="p">:</span> <span class="nb">float</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">num_segments</span><span class="p">:</span> <span class="nb">int</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span>
<span class="n">add_line</span><span class="p">(</span><span class="n">a</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">thickness</span><span class="p">:</span> <span class="nb">float</span><span class="o">=</span><span class="mf">1.0</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span>
<span class="n">add_quad</span><span class="p">(</span><span class="n">a</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">d</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">thickness</span><span class="p">:</span> <span class="nb">float</span><span class="o">=</span><span class="mf">1.0</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span>
<span class="n">add_quad_filled</span><span class="p">(</span><span class="n">a</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">d</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span>
<span class="n">add_rect</span><span class="p">(</span><span class="n">a</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">rounding</span><span class="p">:</span> <span class="nb">float</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">rounding_corners_flags</span><span class="p">:</span> <span class="nb">int</span><span class="o">=</span><span class="n">Corner</span><span class="o">.</span><span class="n">All</span><span class="p">,</span> <span class="n">thickness</span><span class="p">:</span> <span class="nb">float</span><span class="o">=</span><span class="mf">1.0</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span>
<span class="n">add_rect_filled</span><span class="p">(</span><span class="n">a</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">rounding</span><span class="p">:</span> <span class="nb">float</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">rounding_corners_flags</span><span class="p">:</span> <span class="nb">int</span><span class="o">=</span><span class="n">Corner</span><span class="o">.</span><span class="n">All</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span>
<span class="n">add_rect_filled_multicolor</span><span class="p">(</span><span class="n">a</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">col_upr_left</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">col_upr_right</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">col_bot_right</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">col_bot_lefs</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span>
<span class="n">add_triangle</span><span class="p">(</span><span class="n">a</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">thickness</span><span class="p">:</span> <span class="nb">float</span><span class="o">=</span><span class="mf">1.0</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span>
<span class="n">add_triangle_filled</span><span class="p">(</span><span class="n">a</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">b</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">c</span><span class="p">:</span> <span class="n">_bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">,</span> <span class="n">col</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="bp">None</span>
</pre></div>
</div>
<p>Simple usage example below:</p>
<div class="figure align-default">
<img alt="hello-world" src="https://i.imgur.com/MU5Vhfl.png" />
</div>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">bimpy</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>

<span class="n">ctx</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Context</span><span class="p">()</span>

<span class="n">ctx</span><span class="o">.</span><span class="n">init</span><span class="p">(</span><span class="mi">1200</span><span class="p">,</span> <span class="mi">1200</span><span class="p">,</span> <span class="s2">&quot;Draw Commands Test&quot;</span><span class="p">)</span>

<span class="k">with</span> <span class="n">ctx</span><span class="p">:</span>
        <span class="n">bimpy</span><span class="o">.</span><span class="n">themes</span><span class="o">.</span><span class="n">set_light_theme</span><span class="p">()</span>

<span class="n">DATA_POINTS</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Int</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="n">CLASTERS</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Int</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>

<span class="n">std</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Float</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>

<span class="n">colors</span> <span class="o">=</span> <span class="p">[</span><span class="mh">0x4b19e6</span><span class="p">,</span> <span class="mh">0x4bb43c</span><span class="p">,</span> <span class="mh">0x19e1ff</span><span class="p">,</span> <span class="mh">0xc88200</span><span class="p">,</span> <span class="mh">0x3182f5</span><span class="p">,</span> <span class="mh">0xb41e91</span><span class="p">,</span> <span class="mh">0xf0f046</span><span class="p">,</span> <span class="mh">0xf032e6</span><span class="p">,</span> <span class="mh">0xd2f53c</span><span class="p">,</span>
                  <span class="mh">0xfabebe</span><span class="p">,</span> <span class="mh">0x008080</span><span class="p">,</span> <span class="mh">0xe6beff</span><span class="p">,</span> <span class="mh">0xaa6e28</span><span class="p">,</span> <span class="mh">0xfffac8</span><span class="p">,</span> <span class="mh">0x800000</span><span class="p">,</span> <span class="mh">0xaaffc3</span><span class="p">,</span> <span class="mh">0x808000</span><span class="p">,</span> <span class="mh">0xffd8b1</span><span class="p">,</span>
                  <span class="mh">0x000080</span><span class="p">,</span> <span class="mh">0x808080</span><span class="p">,</span> <span class="mh">0xFFFFFF</span><span class="p">,</span> <span class="mh">0x000000</span><span class="p">]</span>

<span class="n">datapoints</span> <span class="o">=</span> <span class="p">[]</span>


<span class="k">def</span> <span class="nf">generate_fake_data</span><span class="p">():</span>
        <span class="n">datapoints</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">CLASTERS</span><span class="o">.</span><span class="n">value</span><span class="p">):</span>
                <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">normal</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="p">(</span><span class="n">DATA_POINTS</span><span class="o">.</span><span class="n">value</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
                <span class="n">alpha</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">()</span>
                <span class="n">scale</span> <span class="o">=</span> <span class="n">std</span><span class="o">.</span><span class="n">value</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
                <span class="n">position</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">*</span> <span class="mi">5</span>
                <span class="n">rotation</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">alpha</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">alpha</span><span class="p">)],</span> <span class="p">[</span><span class="o">-</span><span class="n">np</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">alpha</span><span class="p">),</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="n">alpha</span><span class="p">)]])</span>
                <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">scale</span><span class="p">)</span>
                <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">rotation</span><span class="p">)</span>
                <span class="n">x</span> <span class="o">+=</span> <span class="n">position</span>
                <span class="n">datapoints</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">x</span><span class="p">,</span> <span class="n">rotation</span><span class="p">,</span> <span class="n">position</span><span class="p">,</span> <span class="n">scale</span><span class="p">))</span>

<span class="n">axis</span> <span class="o">=</span> <span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]])</span>

<span class="k">while</span> <span class="ow">not</span> <span class="n">ctx</span><span class="o">.</span><span class="n">should_close</span><span class="p">():</span>
        <span class="n">ctx</span><span class="o">.</span><span class="n">new_frame</span><span class="p">()</span>

        <span class="n">bimpy</span><span class="o">.</span><span class="n">set_next_window_pos</span><span class="p">(</span><span class="n">bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="mi">20</span><span class="p">),</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Condition</span><span class="o">.</span><span class="n">Once</span><span class="p">)</span>
        <span class="n">bimpy</span><span class="o">.</span><span class="n">set_next_window_size</span><span class="p">(</span><span class="n">bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">(</span><span class="mi">800</span><span class="p">,</span> <span class="mi">600</span><span class="p">),</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Condition</span><span class="o">.</span><span class="n">Once</span><span class="p">)</span>
        <span class="n">bimpy</span><span class="o">.</span><span class="n">begin</span><span class="p">(</span><span class="s2">&quot;Drawings&quot;</span><span class="p">)</span>

        <span class="n">window_pos</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">get_window_pos</span><span class="p">()</span>

        <span class="n">center</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">(</span><span class="mi">100</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span> <span class="o">+</span> <span class="n">window_pos</span>
        <span class="n">m</span> <span class="o">=</span> <span class="mf">100.0</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">datapoints</span><span class="p">)):</span>
                <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">R</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">S</span><span class="p">)</span> <span class="o">=</span> <span class="n">datapoints</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>

                <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
                        <span class="n">point</span> <span class="o">=</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">(</span><span class="n">x</span><span class="p">[</span><span class="n">j</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">x</span><span class="p">[</span><span class="n">j</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span>
                        <span class="n">bimpy</span><span class="o">.</span><span class="n">add_circle_filled</span><span class="p">(</span><span class="n">point</span> <span class="o">*</span> <span class="n">m</span> <span class="o">+</span> <span class="n">center</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mh">0xAF000000</span> <span class="o">+</span> <span class="n">colors</span><span class="p">[</span><span class="n">i</span><span class="p">],</span> <span class="mi">100</span><span class="p">)</span>

                <span class="n">axis_</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">S</span> <span class="o">*</span> <span class="mf">2.0</span><span class="p">)</span>
                <span class="n">axis_</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">matmul</span><span class="p">(</span><span class="n">axis_</span><span class="p">,</span> <span class="n">R</span><span class="p">)</span> <span class="o">+</span> <span class="n">P</span>

                <span class="n">bimpy</span><span class="o">.</span><span class="n">add_line</span><span class="p">(</span>
                        <span class="n">center</span> <span class="o">+</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">(</span><span class="n">axis_</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">axis_</span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="n">m</span><span class="p">,</span>
                        <span class="n">center</span> <span class="o">+</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">(</span><span class="n">axis_</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">axis_</span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="n">m</span><span class="p">,</span>
                        <span class="mh">0xFFFF0000</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>

                <span class="n">bimpy</span><span class="o">.</span><span class="n">add_line</span><span class="p">(</span>
                        <span class="n">center</span> <span class="o">+</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">(</span><span class="n">axis_</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">axis_</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="n">m</span><span class="p">,</span>
                        <span class="n">center</span> <span class="o">+</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">(</span><span class="n">axis_</span><span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">0</span><span class="p">],</span> <span class="n">axis_</span><span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">])</span> <span class="o">*</span> <span class="n">m</span><span class="p">,</span>
                        <span class="mh">0xFFFF0000</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>

        <span class="n">bimpy</span><span class="o">.</span><span class="n">end</span><span class="p">()</span>

        <span class="n">bimpy</span><span class="o">.</span><span class="n">set_next_window_pos</span><span class="p">(</span><span class="n">bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="mi">640</span><span class="p">),</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Condition</span><span class="o">.</span><span class="n">Once</span><span class="p">)</span>
        <span class="n">bimpy</span><span class="o">.</span><span class="n">set_next_window_size</span><span class="p">(</span><span class="n">bimpy</span><span class="o">.</span><span class="n">Vec2</span><span class="p">(</span><span class="mi">800</span><span class="p">,</span> <span class="mi">140</span><span class="p">),</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">Condition</span><span class="o">.</span><span class="n">Once</span><span class="p">)</span>
        <span class="n">bimpy</span><span class="o">.</span><span class="n">begin</span><span class="p">(</span><span class="s2">&quot;Controls&quot;</span><span class="p">)</span>

        <span class="n">bimpy</span><span class="o">.</span><span class="n">input_int</span><span class="p">(</span><span class="s2">&quot;Data points count&quot;</span><span class="p">,</span> <span class="n">DATA_POINTS</span><span class="p">)</span>
        <span class="n">bimpy</span><span class="o">.</span><span class="n">input_int</span><span class="p">(</span><span class="s2">&quot;Clasters count&quot;</span><span class="p">,</span> <span class="n">CLASTERS</span><span class="p">)</span>

        <span class="n">bimpy</span><span class="o">.</span><span class="n">slider_float</span><span class="p">(</span><span class="s2">&quot;std&quot;</span><span class="p">,</span> <span class="n">std</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">bimpy</span><span class="o">.</span><span class="n">button</span><span class="p">(</span><span class="s2">&quot;Generate data&quot;</span><span class="p">):</span>
                <span class="n">generate_fake_data</span><span class="p">()</span>

        <span class="n">bimpy</span><span class="o">.</span><span class="n">end</span><span class="p">()</span>

        <span class="n">ctx</span><span class="o">.</span><span class="n">render</span><span class="p">()</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="acknowledgements">
<h2>Acknowledgements<a class="headerlink" href="#acknowledgements" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><p>robobuggy <a class="reference external" href="https://github.com/gfannes">https://github.com/gfannes</a></p></li>
<li><p>njazz <a class="reference external" href="https://github.com/njazz">https://github.com/njazz</a></p></li>
<li><p>Florian Rott <a class="reference external" href="https://github.com/sauberfred">https://github.com/sauberfred</a></p></li>
<li><p>zakx <a class="reference external" href="https://github.com/zakx">https://github.com/zakx</a></p></li>
<li><p>Joel Linn <a class="reference external" href="https://github.com/JoelLinn">https://github.com/JoelLinn</a></p></li>
</ul>
</div>
<div class="section" id="indices-and-tables">
<h2>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h2>
<ul class="simple">
<li><p><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></p></li>
<li><p><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></p></li>
<li><p><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></p></li>
</ul>
</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="bimpy.html" class="btn btn-neutral float-right" title="bimpy - References" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2020, Stanislav Pidhorskyi

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>